<link type="text/css" href="/public/library/jquery/calendar/excite-bike/ui.all.css" rel="stylesheet" media="screen" />
<link rel="stylesheet" href="/public/library/jquery/calendar/excite-bike/jquery-ui-1.7.1.custom.css" type="text/css" media="screen" />

<script type="text/javascript" src="/public/library/jquery/calendar/amlich.js"></script>
<script type="text/javascript" src="/public/library/jquery/calendar/ui.core.js"></script>
<script type="text/javascript" src="/public/library/jquery/calendar/ui.datepicker.js"></script>
<script type="text/javascript" src="/public/library/jquery/calendar/ui.datepicker-lang.js"></script>
<script src="/public/library/hvn/place.js" type="text/javascript"></script>
<script type="text/javascript" src="/public/library/hvn/captcha.redraw.js"></script>
<script src="/public/library/hvn/event.js" type="text/javascript"></script>
<script src="/public/library/autocomplete/autocomplete.js" type="text/javascript"></script>
<link rel="stylesheet" href="/public/library/autocomplete/autocomplete.css" type="text/css">
<style type="text/css">
    .belongToLi
    {
    	display: inline;
    	list-style-type: none;
    	padding-right: 20px; 
    }
    </style>

<div class="box white_bg">
    
<div class="success-message">
	<?if(isset($this->viewParams['successMessage'])) :?><?=$this->viewParams['successMessage']?><?endif?>
</div>
<div class="error-message">
	<?if(isset($this->viewParams['errorMessage'])) :?><?=$this->viewParams['errorMessage']?><?endif?>
</div>

<script language="Javascript">

$(function(){
	
	$("form").submit(function(){
		var tmp = '';
		var ids = '';
		var dis = '';
		$("#belong_to_names ul li").each(function(i){
			//get ids: $(this).attr('name')
			//get name, ids and distance
			if (tmp == '' && ids == '')
			{
				tmp = $(this).find("span:first").text();
				ids = $(this).attr('name');
				//dis = $(this).find("span:last").text();
			}
			else
			{
				tmp = tmp + ',' + $(this).find("span:first").text();
				ids = ids + ',' + $(this).attr('name');
				//dis = dis + ',' + $(this).find("span:last").text();
			}
		});
		if(ids)
		{
			$("#belong_to_ids").val(ids);
			$("#belong_to_names_submit").val(tmp);
		}
		else
		{
			<?if(isset($this->viewParams['place_id'])) :?>
				$("#belong_to_ids").val(<?=$this->viewParams['place_id']?>);
			<?endif?>
			<?if(isset($this->viewParams['belong_to_names_submit'])) :?>
				$("#belong_to_names_submit").val('<?=$this->viewParams['belong_to_names_submit']?>');
			<?endif?>
		}
	});
	
	$("#belong_to_ac_input").attr('autocomplete', 'OFF');
	
	
	var mode = '';
    getAddress(mode); //function in place.js
    getCategoryType(mode);
	setAutoComplete("belong_to_ac_input", "belong_to_ids", "belong_to_names", "results", "/en/place/ajax/autocomplete?part=");
	
	$('.editPlace').openDOMWindow({ 
			height:300, 
			width:400, 
			eventType:'click',
			overlay:0, 
			windowBGColor:'#FFFF00', 
			borderColor:'#5D5DF4', 
			overlayOpacity:15
	}); 
	$('.closePlaceDOMWindow').closeDOMWindow({eventType:'click'}); 
	
	$('.showAddressPlace').click(function(){
		$(".tourCity").toggle();
		return false;
	});
});
</script>
<h1 style="padding-left:10px"> <?=t(216) ?></h1>
<br/>
<form id="newEvent" accept-charset="UTF-8" action="<?= $this->escape($this->viewParams['form']->getAction()) ?>"
      method="<?= $this->escape($this->viewParams['form']->getMethod()) ?>">

<?if($this->viewParams['mode'] != "new"):?>
<br/>
<?endif?>
<div style="display:none">
	<input type="hidden" id="belong_to_ids" name="belong_to_ids" value="<?if(isset($this->viewParams['place_id'])) :?><?=$this->viewParams['place_id']?><?endif?>"/>
	<input type="hidden" id="belong_to_names_submit" name="belong_to_names_submit" value="<?if(isset($this->viewParams['belong_to_names_submit'])) :?><?=$this->viewParams['belong_to_names_submit']?><?endif?>"/>
	<input type="hidden" id="distance" name="distance" value="<?=$this->viewParams['dis']?>"/>
</div>	


<!-- if place already exists -->
<?if(isset($this->viewParams['place_id'])):?>
You are adding events to place <b><?=$this->viewParams['belong_to_names_submit']?></b> (#<?=$this->viewParams['place_id']?> -- City Name: <b><?=$this->viewParams['cityName']?></b>): 
<br/>
<?endif?>
<fieldset class="expansible"><legend><span><?=t(794) ?></span></legend>
<div>
<table>
<tr>
	<td width="100px"><?=t(13)?></td>
	<td><?=$this->viewParams['form']->title ?>
		<? if(!empty($this->viewParams['form']->eventLanguage)) :?>
			<?=$this->viewParams['form']->eventLanguage ?>
		<?endif ?>
	</td>
</tr>
<tr>
	<td width="100px"><?=t(15)?></td>
	<td><?=$this->viewParams['form']->keywords?></td>
</tr>
<tr>	
	<td width="100px"><?=t(14)?></td>
	<td><?=$this->viewParams['form']->category_event ?></td>
</tr>
</table>	
</div>
</fieldset>

<fieldset  class="expansible"> <legend><span><?=t(777) ?></span></legend> 
<div>
 <?=t(765)?> <?=t(701)?> (<b style="color:blue">
 <?if(isset($this->viewParams['belong_to_names_submit'])) :?><?=$this->viewParams['belong_to_names_submit']?><?endif?>
  <?if(isset($this->viewParams['place_id'])) :?><?='#'.$this->viewParams['place_id']?><?endif?></b>)
<a href="#inlinePlace" class="editPlace" title="<?=t(217) ?>" >Edit</a>
<div>
<div>
	<span id="belong_to_names"> <ul></ul></span>
</div>	

<div> 
(<?=t(143) ?> <a href="javascript:void()" class="showAddressPlace" title="<?=t(218) ?>"> <?=t(777) ?></a>) 
</div>
<table class="tourCity" style="display:none;">
	<tr>
		<td width="100px"><?=t(792) ?>:</td>
		<td><?= $this->viewParams['form']->city_id?></td>
	</tr>
	<tr id="district">
		<td ><?=t(771) ?>:</td>
		<td><?= $this->viewParams['form']->district_id?></td>
	</tr>
	<tr>
	<td><?=t(789) ?>:</td>
	<td><?= $this->viewParams['form']->village_id ?></td>
	</tr>
	<tr>
		<td><?=t(790) ?>:</td>
		<td><?= $this->viewParams['form']->address5 ?></td>
	</tr>
	<tr>
		<td><?=t(791) ?>:</td>
		<td><?= $this->viewParams['form']->address6 ?></td>
	</tr>
	<tr>
		<td><?=t(781) ?>:</td>
		<td><?= $this->viewParams['form']->address7 ?></td>
	</tr>
	<tr>
		<td><?=t(783) ?>:</td>
		<td><?= $this->viewParams['form']->address8 ?></td>
	</tr>
	<tr>
		<td><?=t(788) ?>:</td>
		<td><?= $this->viewParams['form']->address9 ?></td>
	</tr>
</table>	
</fieldset>
<!--  DOM Window Place -->
<div id="inlinePlace" style="display: none;"> 
	<table>
		<tr>
			<td><?=t(113) ?>:</td>
			<td><?= $this->viewParams['form']->category?></td>
		</tr>
		<tr>
			<td><?=t(115) ?>:</td>
			<td><?= $this->viewParams['form']->rtype?></td>
		</tr>
		<tr>
			<td><?=t(765) ?>:</td>
			<td><input type="text" id="belong_to_ac_input" name="belong_to_ac_input"/> <span id="newBelongToPlaceId"></span></td>
			<td> <div id="resultID"></div></td>
		</tr>
		<tr>	
			<td></td>
			<td><input type="text" id="length" />(km)</td>
		</tr>
		<tr>
			<td></td>
			<td><div align="right">
				<input type="button" value="Add" class="belongButton" />
				<input type="button" value="Close" class="closePlaceDOMWindow" />
				</div>
			</td>
		</tr>
		</table>
</div>
<!--  time & frequency -->
<fieldset  class="expansible"> <legend><span><?=t(215)?></span></legend>
<div>
	<span style="margin-right:60px"><?=t(16)?></span>
	<?=$this->viewParams['form']->frequency ?>
	<div id="eventTime">
	<span style="margin-right:60px"><?=t(17)?></span><?=$this->viewParams['form']->startHour ?>h<?=$this->viewParams['form']->startMinute ?>p &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?=t(18)?>:<?=$this->viewParams['form']->finishHour ?>h<?=$this->viewParams['form']->finishMinute ?>p
	</div>
	<div id ="eventDay" style="display:none">
	<span style="margin-right:60px"><?=t(19)?></span> <?=$this->viewParams['form']->startDay ?> &nbsp;&nbsp;&nbsp;--------------&nbsp;&nbsp;&nbsp; <?=$this->viewParams['form']->finishDay ?>
	</div>
	
	<div id = "eventDate">
	<span style="margin-right:60px"><?=t(20)?></span>
	<?=$this->viewParams['form']->startDate ?> &nbsp;&nbsp;&nbsp;--------------&nbsp;&nbsp;&nbsp; <?=$this->viewParams['form']->finishDate ?>
	 &nbsp; <?=t(28)?> <?=$this->viewParams['form']->calendarType?>
	</div>
	Other <br/><?=$this->viewParams['form']->other_frequency ?>
</div>
</fieldset>

<fieldset  class="expansible"> <legend><span><?=t(21)?></span></legend>
<div>
	<?=$this->viewParams['form']->description?>
	<br/>
</div>	
</fieldset>

<? if(!empty($this->viewParams['form']->captcha_newevent)) :?>
<div>
<?=$this->viewParams['form']->captcha_newevent ?>
<a href="javascript:void()" class="redraw"> <?=t(22)?></a>
</div>
<?endif ?>

<? if(isset($this->viewParams['form']->status)) :?>
<br/>
<?=t(2)?> :<?=$this->viewParams['form']->status ?>
<br/>
<?endif ?>
<?=$this->viewParams['form']->submit ?>
<input type ="hidden" name = "id" value = "<?if(isset($this->viewParams['id'])):?><?=$this->viewParams['id']; ?><?endif?>" />
<input type ="hidden" name = "article_id" value = "<?if(isset($this->viewParams['article_id'])):?><?=$this->viewParams['article_id']; ?><?endif?>" />

</form>

</div>

<script>
$(function(){
	$("#frequency").trigger("change");
});
</script>
